package pacman.objects;

import java.awt.Color;
import java.awt.Graphics;
import pacman.skills.*;

public class PacMan extends Moveable
{
  private int level;
  private int experience;
  public int activeSkill;

  private Skill[] skill;

  public PacMan(float posX, float posY)
  {
    this.skill = new Skill[15];
    this.health = 1;
    this.maxHealth = 1;
    this.visible = true;

    this.dead = false;

    this.posX = posX * cellSize + cellSize / 2;
    this.posY = posY * cellSize + cellSize / 2;
    this.headingAngle = 0;
    this.speed = (float)15;
    this.charSize = (float)0.6;

    this.level = 1;
    this.experience = 0;
    this.activeSkill = 1;

    skill[0] = new Bite();
    skill[1] = new Bite2();
    skill[2] = new Bite3();
    skill[3] = new Bite4();
    skill[4] = new Bite2X();
    skill[5] = new Bite22X();
    skill[6] = new Bite4X();
    skill[7] = new BiteHall();
    skill[8] = new BiteHall2();
    skill[9] = new BiteHall3();
    skill[10] = new Sickle();
    skill[11] = new Spear();
    skill[12] = new TeleNear();
    skill[13] = new TeleNear2();
    skill[14] = new TeleNear2X();
    
    //Insert color
  }

  public void levelUp(){
    this.level += 1;
    this.maxHealth += 1;
    this.speed += (float)0.1;
  }
  
  public void increaseExperience(int exp)
  {
    this.experience+=exp;
    if (this.experience > 1000 * this.level)
    {
      this.experience -= 1000 * this.level;
      levelUp();
    }
  }

  public void nextSkill()
  {
      if(activeSkill < 14)
         this.activeSkill++;
      else activeSkill = 1;
  }

  public void prevSkill()
  {
      if(activeSkill > 1)
        this.activeSkill--;
      else activeSkill = 14;
  }

  public void Attack(Ghost ghost)
  {
    if(skill[activeSkill].Active())
       skill[activeSkill].Attack(ghost);
  }

  public void basicAttack(Ghost ghost)
  {
    skill[0].Attack(ghost);
  }

  public void render(Graphics g)
  {
    g.setColor(Color.RED);
    g.fillArc((int)(this.posX - charSize * cellSize / 2), (int)(this.posY - charSize * cellSize / 2), (int)(charSize * cellSize), (int)(charSize * cellSize), (int)(headingAngle * 180 / Math.PI) + 30, 300);
  }

  public boolean eat(Static object)
  {
    if (object instanceof Dots)
    {
      increaseExperience(10);
      return true;
    }
    return false;
  }
}
